<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::FileUpdateChecker</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveSupport::FileUpdateChecker 
            
                <span class="parent">&lt; 
                    
                    <a href="../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/activesupport/lib/active_support/file_update_checker_rb.html">activesupport/lib/active_support/file_update_checker.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p><a href="FileUpdateChecker.html">FileUpdateChecker</a> specifies the API
used by <a href="../Rails.html">Rails</a> to watch files and control
reloading. The API depends on four methods:</p>
<ul><li>
<p><code>initialize</code> which expects two parameters and one block as
described below.</p>
</li><li>
<p><code>updated?</code> which returns a boolean if there were updates in the
filesystem or not.</p>
</li><li>
<p><code>execute</code> which executes the given block on initialization and
updates the latest watched files and timestamp.</p>
</li><li>
<p><code>execute_if_updated</code> which just executes the block if it was
updated.</p>
</li></ul>

<p>After initialization, a call to <code>execute_if_updated</code> must
execute the block only if there was really a change in the filesystem.</p>

<p>This class is used by <a href="../Rails.html">Rails</a> to reload the <a
href="../I18n.html">I18n</a> framework whenever they are changed upon a new
request.</p>

<pre>i18n_reloader = ActiveSupport::FileUpdateChecker.new(paths) do
  I18n.reload!
end

ActionDispatch::Reloader.to_prepare do
  i18n_reloader.execute_if_updated
end</pre>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FileUpdateChecker.html#method-i-execute">execute</a>,
              </li>
            
              
              <li>
                <a href="FileUpdateChecker.html#method-i-execute_if_updated">execute_if_updated</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FileUpdateChecker.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>U</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FileUpdateChecker.html#method-i-updated-3F">updated?</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(files, dirs={}, &amp;block)
            
            <a href="FileUpdateChecker.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>It accepts two parameters on initialization. The first is an array of files
and the second is an optional hash of directories. The hash must have
directories as keys and the value is an array of extensions to be watched
under that directory.</p>

<p>This method must also receive a block that will be called once a path
changes. The array of files and list of directories cannot be changed after
<a href="FileUpdateChecker.html">FileUpdateChecker</a> has been
initialized.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/019df9887519701b321c668c1d27d5c0c26fee7a/activesupport/lib/active_support/file_update_checker.rb#L38" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/file_update_checker.rb, line 38</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">files</span>, <span class="ruby-identifier">dirs</span>={}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@files</span> = <span class="ruby-identifier">files</span>.<span class="ruby-identifier">freeze</span>
  <span class="ruby-ivar">@glob</span>  = <span class="ruby-identifier">compile_glob</span>(<span class="ruby-identifier">dirs</span>)
  <span class="ruby-ivar">@block</span> = <span class="ruby-identifier">block</span>

  <span class="ruby-ivar">@watched</span>    = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@updated_at</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-ivar">@last_watched</span>   = <span class="ruby-identifier">watched</span>
  <span class="ruby-ivar">@last_update_at</span> = <span class="ruby-identifier">updated_at</span>(<span class="ruby-ivar">@last_watched</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-execute">
            
              <b>execute</b>()
            
            <a href="FileUpdateChecker.html#method-i-execute" name="method-i-execute" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Executes the given block and updates the latest watched files and
timestamp.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-execute_source')" id="l_method-i-execute_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/019df9887519701b321c668c1d27d5c0c26fee7a/activesupport/lib/active_support/file_update_checker.rb#L72" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-execute_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/file_update_checker.rb, line 72</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">execute</span>
  <span class="ruby-ivar">@last_watched</span>   = <span class="ruby-identifier">watched</span>
  <span class="ruby-ivar">@last_update_at</span> = <span class="ruby-identifier">updated_at</span>(<span class="ruby-ivar">@last_watched</span>)
  <span class="ruby-ivar">@block</span>.<span class="ruby-identifier">call</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-ivar">@watched</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@updated_at</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-execute_if_updated">
            
              <b>execute_if_updated</b>()
            
            <a href="FileUpdateChecker.html#method-i-execute_if_updated" name="method-i-execute_if_updated" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Execute the block given if updated.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-execute_if_updated_source')" id="l_method-i-execute_if_updated_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/019df9887519701b321c668c1d27d5c0c26fee7a/activesupport/lib/active_support/file_update_checker.rb#L82" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-execute_if_updated_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/file_update_checker.rb, line 82</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">execute_if_updated</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">updated?</span>
    <span class="ruby-identifier">execute</span>
    <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-updated-3F">
            
              <b>updated?</b>()
            
            <a href="FileUpdateChecker.html#method-i-updated-3F" name="method-i-updated-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Check if any of the entries were updated. If so, the watched and/or
updated_at values are cached until the block is executed via
<code>execute</code> or <code>execute_if_updated</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-updated-3F_source')" id="l_method-i-updated-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/019df9887519701b321c668c1d27d5c0c26fee7a/activesupport/lib/active_support/file_update_checker.rb#L53" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-updated-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/file_update_checker.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">updated?</span>
  <span class="ruby-identifier">current_watched</span> = <span class="ruby-identifier">watched</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@last_watched</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">current_watched</span>.<span class="ruby-identifier">size</span>
    <span class="ruby-ivar">@watched</span> = <span class="ruby-identifier">current_watched</span>
    <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">current_updated_at</span> = <span class="ruby-identifier">updated_at</span>(<span class="ruby-identifier">current_watched</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@last_update_at</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">current_updated_at</span>
      <span class="ruby-ivar">@watched</span>    = <span class="ruby-identifier">current_watched</span>
      <span class="ruby-ivar">@updated_at</span> = <span class="ruby-identifier">current_updated_at</span>
      <span class="ruby-keyword">true</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    